<template>
  <div class="mod-config editViewContainer">
    <split-pane class="splitPane" :min-percent='10' :default-percent='10' split="vertical">
      <template slot="paneL">
        <div class="treeViewContainer">
          <tree-view ref="treeView" :treeData="statusTreeList" :checkChangedHandler="getDataList"></tree-view>
        </div>
      </template>
      <template slot="paneR">
        <table-view ref="view"
                    :searchAttrs="searchAttrs"
                    :primaryKey="primaryKey"
                    :listApiName="listApiName"
                    :showAttrs="showAttrs"
                    :exportApiName="exportApiName"
        >
          <template v-slot:foot="{scope}">
            <el-tooltip  class="item" effect="dark" content="更新质检状态" placement="bottom" :hide-after="1800" :open-delay="800">
              <el-button  type="text" size="small"  @click="openQualityApprovalDialog(R.prop('row', scope))"  >更新质检</el-button>
            </el-tooltip>
            <el-tooltip   class="item" effect="dark" content="查看质检记录" placement="bottom" :hide-after="1800" :open-delay="800">
              <el-button  type="text" size="small" @click="openQualityApprovalListDialog(R.prop('row', scope))">查看记录</el-button>
            </el-tooltip>
            <!--         @click="openBoxOrderStatusDialog(R.prop('row', scope))"-->
          </template>
        </table-view>
        <add-or-update  v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>

        <el-dialog title="查看质检记录" :visible.sync="qualityApprovalDialog" v-loading="qualityApprovalLoading" width="50%">
          <el-table :data="qualityApprovalList" border style="width: 100%;">
<!--            <el-table-column prop="weight" header-align="center" align="center" label="克数"></el-table-column>-->
<!--            <el-table-column prop`="putInStorageValue" header-align="center" align="center" label="对方的是对方"></el-table-column>-->
<!--            <el-table-column prop="leaveStorageValue" header-align="center" align="center" label="出库数量"></el-table-column>-->
<!--            <el-table-column prop="inventory" header-align="center" align="center" label="剩余数量"></el-table-column>-->
          </el-table>
          <span slot="footer" class="dialog-footer">
            <el-button @click="qualityApprovalDialog = false">取 消</el-button>
            <el-button type="primary" @click="qualityApprovalDialog = false">确 定</el-button>
        </span>
        </el-dialog>


      </template>
    </split-pane>


  </div>
</template>


<script>
import tableView from '@/components/tableView'
import basicMixins from '@/utils/commonViewMixins'
import treeView from '@/components/treeView'


import {mRequest} from '@/utils/request'
import {exportHandle, isAuth} from '@/utils'
import AddOrUpdate from './qualityapprovalinfo-add-or-update'
export default {
  mixins: [basicMixins],
  data() {
    return {
      statusTreeList: [],
      modelInfoVisible: false,
      productInfoVisible: false,
      purchaseContractVisible: false,
      addOrUpdateVisible: false,
      supplierList: [],
      modelInfoList: [],
      orderDetailList: [],
      supplierId: '',
      contractTime: '',
      deliveryTime: '',
      totalAmount: 0,
      remark: '',
      tableListData: [],
      primaryKey: 'id',
      qualityApprovalList: [],
      qualityApprovalLoading: false,
      qualityApprovalDialog: false,
      listApiName: 'purchaseApi/listPurchaseModelList',
      deleteApiName: 'purchaseApi/deletePurchaseModel',
      exportApiName: 'purchaseApi/getPurchaseModel',
      saveAuthName: 'purchase:purchasemodel:save',
      deleteAuthName: 'purchase:purchasemodel:delete',
      searchAttrs: {
        contractPurchaseId: {
          type: 'autoComplete',
          placeholder: '请输入采购合同号',
          querySearchApiName: 'contractApi/getContractPurchaseInfoList'
        },
        productNo: {
          label: '产品编号',
          placeholder: '请输入产品编号'
        },
        supplierId:{
          type: 'autoComplete',
          placeholder: '请输入供应商',
          querySearchApiName: 'supplierApi/getSupplierList'
        },
        status: {
          type: 'func',
          dataFunc: () => {
            return this.$refs.treeView.$refs.treeForm.getCheckedKeys()[0]
          }
        }
      },
      showAttrs: {
        supplierName: {
          label: '供应商',
          width: 120
        },
        userName:{
          label: '申请人'
        },
        status: {
          label: '状态',
          type: 'radio',
          items: [
            {value: 0, text: '待采购', tagType: 'info'},
            {value: 1, text: '采购申请待审批'},
            {value: 2, text: '采购进行中'},
            {value: 3, text: '采购逾期预警',tagType:'warning'},
            {value: 4, text: '采购完成', tagType: 'success'},
            {value: 6, text: '采购暂停', tagType: 'danger'},
            {value: 7, text: '采购入库进行中', tagType: 'warning'},
            {value: 8, text: '采购入库完成', tagType: 'success'},
            {value: 17, text: '挑选', tagType: 'warning'},
            {value: 18, text: '合格', tagType: 'success'},
            {value: 19, text: '不合格', tagType: 'danger'},
            {value: 20, text: '特采', tagType: 'success'}
          ]
        },
        productNo: {label: '产品名称'},
        modelNo: {
          label: '模具编号'
        },
        successMo: {
          label: '成模'
        },
        primaryMo: {
          label: '初模'
        },
        menTou: {
          label: '闷头'
        },
        louDou: {
          label: '漏斗'
        },
        modelDrawingId: {
          label: '图纸',
          showKey: 'modelNo', type: 'file', width: 140

        },
        qualityFilePath:{
          label: '抽检报告', showKey: 'modelNo', type: 'file', width: 140

        },
        qualityRemark:{
          label:"质检备注"
        },
        qualityStatus:{
          label:"质检状态",
          type: 'radio',
          items: [
            {value: 17, text: '挑选', tagType: 'warning'},
            {value: 18, text: '合格', tagType: 'success'},
            {value: 19, text: '不合格', tagType: 'danger'},
            {value: 20, text: '特采', tagType: 'success'}
          ]

        }

      }
    }
  },
  components: {
    treeView,
    tableView,
    AddOrUpdate
  },
  methods: {
    openModelInfoDialog(cb) {
      this.modelInfoVisible = true
      this.$nextTick(() => {
        if (!this.R.isNil(this.$refs.modelInfo)) {
          this.$refs.modelInfo.init(null, {status: 1}, cb)
        }
      })
    },
    statusTreeListInit() {
      mRequest('systemApi/getPurchaseStatusList', {}, (res) => {
        this.statusTreeList = this.R.pathOr([], ['data', 'list'], res)
      })
    },
    openQualityApprovalListDialog(cb) {
      this.qualityApprovalDialog=true
      console.log(cb)
    },
    //qualityApprovalList
    exportPlantFunc(rows){
      this.supplierId = ''
      this.contractTime = ''
      this.deliveryTime = ''
      this.totalAmount = 0
      this.purchaseType = 6
      this.remark = ''
      this.purchaseContractVisible = true
      this.initOrderDetailList()
      this.initModelInfoList()
      this.initSupplierList()
      this.tableListData = rows
    },
    initSupplierList() {
      mRequest('supplierApi/getSupplierList', {}, (res) => {
        this.supplierList = this.R.pathOr([], ['data', 'list'], res)
      })
    },
    initOrderDetailList() {
      mRequest('orderApi/getOrderDetailList', {}, (res) => {
        this.orderDetailList = this.R.pathOr([], ['data', 'list'], res)
      })
    },
    initModelInfoList() {
      mRequest('modelApi/getModelInfoList', {}, (res) => {
        this.modelInfoList = this.R.pathOr([], ['data', 'list'], res)
      })
    },
    openProductInfoDialog(cb) {
      this.productInfoVisible = true
      this.$nextTick(() => {
        if (!this.R.isNil(this.$refs.productInfo)) {
          this.$refs.productInfo.init(null, {status: 1}, cb)
        }
      })
    },
    downPurchaseModelDetail(){
      exportHandle('purchaseApi/getPurchaseModelDetailExport', {})
    },
    openQualityApprovalDialog(cb) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        if (!this.R.isNil(this.$refs.addOrUpdate)) {
          this.$refs.addOrUpdate.init(null, {qualityType: 1,purchaseModelId:cb.id}, cb)
        }
      })
    }
  },
  mounted() {
    this.statusTreeListInit()
  }
}
</script>
